// 移动端导航菜单切换
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');

hamburger.addEventListener('click', () => {
    navLinks.classList.toggle('active');
});

// 点击导航链接时关闭移动端菜单
document.querySelectorAll('.nav-links a').forEach(link => {
    link.addEventListener('click', () => {
        navLinks.classList.remove('active');
    });
});

// 菜单标签切换
const tabs = document.querySelectorAll('.tab');
const menuCategories = document.querySelectorAll('.menu-category');

tabs.forEach(tab => {
    tab.addEventListener('click', () => {
        // 移除所有活动状态
        tabs.forEach(t => t.classList.remove('active'));
        menuCategories.forEach(category => category.classList.remove('active'));
        
        // 添加当前活动状态
        tab.classList.add('active');
        const tabId = tab.getAttribute('data-tab');
        document.getElementById(tabId).classList.add('active');
    });
});

// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function(e) {
        e.preventDefault();
        
        const targetId = this.getAttribute('href');
        if (targetId === '#') return;
        
        const targetElement = document.querySelector(targetId);
        if (targetElement) {
            window.scrollTo({
                top: targetElement.offsetTop - 70,
                behavior: 'smooth'
                });
        }
    });
});

// 表单提交处理
const reservationForm = document.getElementById('reservationForm');
if (reservationForm) {
    reservationForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        // 获取表单数据
        const name = document.getElementById('name').value;
        const phone = document.getElementById('phone').value;
        
        // 简单验证
        if (name && phone) {
            // 显示成功消息
            alert(`谢谢您，${name}！您的预订请求已提交。我们将会尽快与您确认。`);
            reservationForm.reset();
        } else {
            alert('请填写必填字段');
        }
    });
}

// 页脚年份自动更新
document.addEventListener('DOMContentLoaded', function() {
    const currentYear = new Date().getFullYear();
    const copyrightElement = document.querySelector('.footer-bottom p');
    if (copyrightElement) {
        copyrightElement.innerHTML = `&copy; ${currentYear} 味觉盛宴. 保留所有权利.`;
    }
});

// 添加滚动动画效果
window.addEventListener('scroll', function() {
    const sections = document.querySelectorAll('section');
    const nav = document.querySelector('header');
    
    // 滚动时改变导航栏样式
    if (window.scrollY > 100) {
        nav.style.padding = '10px 0';
        nav.style.boxShadow = '0 5px 20px rgba(0, 0, 0, 0.1)';
    } else {
        nav.style.padding = '15px 0';
        nav.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
    }
    
    // 为可见区域的元素添加动画类
    sections.forEach(section => {
        const sectionTop = section.getBoundingClientRect().top;
        const windowHeight = window.innerHeight;
        
        if (sectionTop < windowHeight - 100) {
            section.style.opacity = '1';
            section.style.transform = 'translateY(0)';
        }
    });
});

// 初始化动画
document.addEventListener('DOMContentLoaded', function() {
    const sections = document.querySelectorAll('section');
    sections.forEach(section => {
        section.style.opacity = '0';
        section.style.transform = 'translateY(20px)';
        section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
    });
    
    // 触发动画
    window.dispatchEvent(new Event('scroll'));
});